package entidades;

import gestordeentidades.persistance.DataBaseObject;
import javafx.beans.property.FloatProperty;
import javafx.beans.property.SimpleFloatProperty;

/**
 * Trabalho DAS - 2014/2015
 *
 * @author a21210380, a21190325, a21210392
 */
public class Ponto extends DataBaseObject {
    private final FloatProperty x;
    private final FloatProperty y;
    
    public Ponto() {
        this.x = new SimpleFloatProperty(0);
        this.y = new SimpleFloatProperty(0);
    }
    
    public Ponto(Ponto p) {
        this.x = new SimpleFloatProperty(p.getX());
        this.y = new SimpleFloatProperty(p.getY());
    }

    public Ponto(float x, float y) {
        this.x = new SimpleFloatProperty(x);
        this.y = new SimpleFloatProperty(y);
    }

    public float getX() {
        return x.floatValue();
    }

    public Ponto setX(float x) {
        this.x.setValue(x);
        return this;
    }

    public float getY() {
        return y.floatValue();
    }

    public Ponto setY(float y) {
        this.y.setValue(y);
        return this;
    }
    
    public Ponto set(float x, float y) {
        this.x.setValue(x);
        this.y.setValue(y);
        return this;
    }
    
    public Ponto set(Ponto ponto) {
        this.x.setValue(ponto.getX());
        this.y.setValue(ponto.getY());
        return this;
    }

    @Override
    public String toString() {
        return "[" + x.floatValue() + ";" + y.floatValue() + ']';
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if(obj instanceof Ponto) {
            Ponto c = (Ponto)obj;
            return x.floatValue() == c.getX() && y.floatValue() == c.getY();
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 29 * hash + Float.floatToIntBits(this.x.floatValue());
        hash = 29 * hash + Float.floatToIntBits(this.y.floatValue());
        return hash;
    }

    public FloatProperty xProperty() {
        return x;
    }

    public FloatProperty yProperty() {
        return y;
    }
}
